package algocasts;

public class P43_strStr {
    public int strstr(String haystack, String needle) {
        if (needle.length() == 0) return 0;
        int n = haystack.length(), m = needle.length();
        for (int i = 0; i <= n-m; ++i) {
            int j = 0, k = i;
            for (; j <m && k<n && needle.charAt(j) == haystack.charAt(k); ++k,++j);
            if (j==needle.length()) return i;
        }
        return -1;
    }
}
